window.ROOT = "";
(function() {
	var serverData = {};
	var serverTable;
	jQuery(document)
			.ready(
					function() {
						serverTable = jQuery('#dataTable')
								.DataTable(
										{
											"serverSide" : true,
											"ordering" : false,
											"ajax" : {
												"dataType" : "json",
												"type" : "get",
												"cache" : false,
												"url" : window.rootPath
														+ '/ui/index/getEventInfoList',
												"data" : function(d) {
													return $.extend({}, d,
															serverData);
												}
											},
											columns : [
													{
														data : null,
														defaultContent : ""
													},
													{
														data : 'registerEventName'
													},
													{
														data : 'registerEventAccTime',
														render : function(data,
																type, full,
																meta) {
															if (data)
																return moment(
																		data)
																		.format(
																				'YYYY/MM/DD HH:mm');
															else
																return '';
														}
													},
													{
														data : 'gridName'
													},
													{
														data : 'eventName'
													},
													{
														data : 'registerEventSeriousLevelTitle'
													},
													{
														data : 'registerEventContent',
														render : function(data,type, full,meta) {
															if (data.length > 15)
																return data.substring(0,15)+"...";
															else
																return data;
														}
													},
													{
														data : 'registerEventMemo',
														render : function(data,type, full,meta) {
															if (data.length > 15)
																return data.substring(0,15)+"...";
															else
																return data;
														}
													},
													{
														data : null,
														defaultContent : "",
														render : function(data,
																type, full,
																meta) {
															var operate = '<button type="button" class="btn btn-sm btn-info selectBtn" title="选择"><i class="fa fa-flag"></i></button>'
															return operate;

														}
													} ],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length
														+ oSettings._iDisplayStart;

												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$(
															'td:eq(0)',
															oSettings.aoData[oSettings.aiDisplay[k]].nTr)
															.text(i + 1);
													k++;
												}

												serverTable.off('click', 'tr');
												serverTable.on('click','tr',function(event) {
													event = event
															|| window.event;
													var target = event.target
															|| event.scrElement;
													var data = serverTable.row(this).data();

													if (target.className
															.indexOf('fa-flag') != -1
															|| target.className
																	.indexOf('selectBtn') != -1) {
														selectData(data);
													}
													return;
												});
											}
										})
					});
	var selectData = function(data) {
		if (!data)
			return;
		window.parent.window.getEventToMap(data);
	}
	jQuery('.togetherBtn').on('click', function() {
		var dataInfo = getSelectData('addUser');
		if (dataInfo.length == 0) {
			message('请选择需要跟踪的人员!');
			return;
		}
		window.parent.window.getUserToMapIds(dataInfo);
	});
	// 获取全选数据
	function getSelectData(group) {
		var obj = $(":checkbox[group=" + group + "]:checked");
		var myArray = new Array();
		var i = 0;
		obj.each(function() {
			myArray[i++] = $(this).attr('dataId');
		});
		return myArray;
	}
	// 全选-取消操作
	$("#allSelect").click(function() {
		var addUser = $(":checkbox[group=addUser]");
		if ($(this).prop("checked")) {
			addUser.each(function() {
				$(this).prop("checked", true);
			});
		} else {
			addUser.each(function() {
				$(this).prop("checked", false);
			});
		}
	});
	// 查询
	jQuery('.searchBtn').on('click', function() {
		serverData.key = jQuery("#search").val();
		serverTable.draw();
	});
	// 撤销查询
	jQuery('.resetBtn').on('click', function() {
		jQuery('#search').val('');
		serverData.key = '';
		serverTable.draw();
	});
})();